package org.tissou.client.Panel_Premier.comptes_tab.ModificationsVisualisation_Comptes;

import org.tissou.client.Interface.Base_Panel;
import org.tissou.client.Services.ArbreDeComptes;
import org.tissou.client.Services.InformationsGlobales;
import org.tissou.client.Services.Compte;
import org.tissou.client.Services.MonException;
import org.tissou.client.Services.RecuperationDonneesService.RecuperateurDonneesServices;
import org.tissou.client.DonneesAAfficher.*;
import org.tissou.client.widgets.Label_MessageInformation;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Claire
 * Date: 03/03/2009
 * Time: 21:12:32
 * To change this template use File | Settings | File Templates.
 */
public class Fenetre_Visualisation_Compte extends Base_Panel {
  DockPanel principal = new DockPanel();
  DockPanel panel_entrees = new DockPanel();
  DockPanel panel_arbrecomptes = new DockPanel();
  DockPanel panel_lignescomptes = new DockPanel();
  ArbreDeComptes comptes = new ArbreDeComptes(InformationsGlobales.personneLoguee.getNom());
  DockPanel panel_date = new DockPanel();
  DateBox datePicker = new DateBox();
  Label label_date = new Label("Je veux voir ce compte avant la date :");
  Button ok = new Button();
  Donnees_Base donnees_lignescompte;

  Label_MessageInformation message_information = new Label_MessageInformation();

  Boolean compteSelectionne = false;
  Boolean lignesAffichees = false;

  protected void MiseEnPlaceStyles() {
    comptes.addStyleName("defaultstyle");
  }


  protected void MiseEnPlaceParametresWidgets() {
    datePicker.setValue(new Date()) ;
    datePicker.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")));
    ok.setText("Go");
  }

  protected void MiseEnPlaceParametresPanel() {
    panel_arbrecomptes.add(comptes, DockPanel.NORTH);
    panel_date.add(label_date, DockPanel.NORTH);
    panel_date.add(datePicker, DockPanel.NORTH);

  }

  protected void MiseEnPlaceActions() {

   ok.addClickHandler(new ClickHandler(){

     @Override
     public void onClick(ClickEvent event) {
       Compte c;
       try{c = comptes.donneLeCompteSelectionne();
       } catch(MonException e){
         message_information.setMessage(Label_MessageInformation.Etat.MAUVAISEENTREE, e.getMessage());
         throw e;
       }
       ParametresQuery parametres = new ParametresQuery.Builder()
           .addCompte(c)
           .addDate(datePicker.getValue())
           .setNombredeligne(20)
           .setOffset(0)
           .setType(TypeDonnee.LIGNECOMPTEREEL)
           .build();

       RecuperateurAfficheurDonnees recuperateur = new RecuperateurAfficheurDonnees(parametres, panel_lignescomptes,
           message_information);
       recuperateur.recupererEtAfficherDonnees();
     }
   });
  }

  protected void MiseEnPlacePanels() {
    principal.add(message_information, DockPanel.NORTH);
    principal.setCellHeight(message_information, "40px");
    principal.setCellHorizontalAlignment(message_information,HasHorizontalAlignment.ALIGN_CENTER);
    panel_entrees.add(panel_date, DockPanel.NORTH);
    panel_entrees.add(panel_arbrecomptes, DockPanel.NORTH);
    panel_entrees.add(ok, DockPanel.NORTH);
    principal.add(panel_entrees, DockPanel.WEST);
    principal.add(panel_lignescomptes, DockPanel.WEST);
  }

  protected Panel donneLePanelPrincipal() {
    return principal;
  }
}
